new Vue({
    el:'#main',
    data:()=>({
        sale_id:$('#sale_id').val(),
        saleLog:[],
        saleList:{},
        costData:[],
        orderList:[],
        payregList:[],
        paymentList:[],
        saleMakeDetail:[],
        deliveryNoteList:[],
        saleOrderRemarkData:[],
        billData:{
            SumProPrice:0,
            SumDiscountPrice:0,
            SumCommissionPrice:0,
            sumCost:0,
            mustPay:0,
            sumPaid:0,
        },
        proNum:0,
        costNum:0,
        paymentAmount:0,
        deliveryNoteDetailData:[],
    }),
    methods:{
        formatUnit:formatUnit,
        getdata(){
            $('.loding').show()
            this.pageSum = 0
            var data={
                id:this.sale_id,
                requestType:'detail'
            }
            $.ajax({
                url:'/admin/sale/checkDetail',
                type:'post',
                data,
                success:(data)=>{
                    data = JSON.parse(data)
                    console.log(data)
                    this.saleLog = data.data.saleLog
                    this.saleList = data.data.saleList
                    this.costData = data.data.costData
                    this.orderList = data.data.orderList
                    // this.payregList = data.data.payregList
                    this.paymentList = data.data.paymentList
                    this.saleMakeDetail = data.data.saleMakeDetail
                    this.deliveryNoteList = data.data.deliveryNoteList
                    // this.saleOrderRemarkData = data.data.saleOrderRemarkData
                    this.countBill()
                    $('.loding').hide()
                }
            })
        },
        countBill(){
            for (var i = 0; i < this.orderList.length; i++) {
                this.billData.SumProPrice += this.orderList[i].price*this.orderList[i].qty
                this.billData.SumDiscountPrice += this.orderList[i].discountPriceSum
                this.billData.SumCommissionPrice += this.orderList[i].commissionPrice

                this.proNum = i+1
            }

            for (var i = 0; i < this.costData.length; i++) {
                if(this.costData[i].options == '+') this.billData.sumCost += this.costData[i].amount
                if(this.costData[i].options == '-') this.billData.sumCost -= this.costData[i].amount

                this.costNum = i+1
            }

            for (var i = 0; i < this.paymentList.length; i++) {
                this.billData.payment += this.paymentList[i].amount
            }

            for (var i = 0; i < this.payregList.length; i++) {
                if(this.payregList[i].status == 1 || this.payregList[i].status == 3)
                    this.billData.sumPaid += this.payregList[i].amount

                this.paymentAmount += this.payregList[i].amount
            }



            this.billData.mustPay = this.billData.SumProPrice - this.billData.SumDiscountPrice + this.billData.sumCost
        },
        // 送货单详情
        deliveryNoteDetail(key){
            this.deliveryNoteDetailData = this.deliveryNoteList[key]
        },


        
        //设置popper组件的配置
        setpopper(e){
            $(e.target).popover({
                trigger: 'hover focus manual',
                placement: ($(e.target).attr("placement") == undefined) ? 'left' : $(e.target).attr("placement"),
                //placement:'left',
                title: $(e.target).attr("title"),
                html: 'true',
                content: $(e.target).find(".content").html(),
                animation: false
            });
        },

    },
    mounted(){
        this.getdata()
    },
    computed:{
        //计算合计
        sumnum(){
            var s = 0;
            var m = 0;
            var w = 0;
            if(this.deliveryNoteDetailData.salePackData != undefined){
                this.deliveryNoteDetailData.salePackData.forEach(e => {
                    s+= Number(e.ctns);//箱数
                    m+= Number(e.volume*e.ctns);//每一个箱号的体积*箱数
                    w+= Number(e.ctn_kgs);//重量
                });    
            }
            return [s,m,w];
        },

        packSum(){
            var c = 0;
            var v = 0;
            var k = 0;
            if(this.saleMakeDetail.salePackData != undefined){
                this.saleMakeDetail.salePackData.forEach(e => {
                    c+= Number(e.ctns);//箱数
                    v+= Number(e.volume*e.ctns);//每一个箱号的体积*箱数
                    k+= Number(e.ctn_kgs);//重量
                });    
            }
            return [c,v,k];
        }
    },
})